/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Service;



import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import org.hibernate.Criteria;
import DB.HibernateUtil;
import DB.ProfesionalExterno;
import com.google.gson.Gson;
/**
 *
 * @author franzel
 */
@WebService()
public class ProfesionalExternoWS {

@WebMethod(operationName = "agregarProfesionalExterno")
    public boolean agregarProfesionalExterno(@WebParam(name = "profesional") ProfesionalExterno profesional){

            return ControladorDeObjetos.saveObject(profesional);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "listarProfesionalesExternos")
    public List<ProfesionalExterno> listarProfesionalesExternos() {
        //TODO write your implementation code here:
        return ControladorDeObjetos.getAllObjectByClassType(ProfesionalExterno.class);
    }

    /**
     * Web service operation
     */


    @WebMethod(operationName = "cargarProfesionalExterno")
    public Object cargarProfesionalExterno(@WebParam(name = "rut") String rut) {
        //TODO write your implementation code here:
        return ControladorDeObjetos.loadObjectByStringId(rut, ProfesionalExterno.class);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "modificarProfesionalExterno")
    public boolean modificarProfesionalExterno(@WebParam(name = "ProfesionalExterno")ProfesionalExterno profesional) {
        return ControladorDeObjetos.updateObject(profesional);
    }


    @WebMethod(operationName = "filtrarProfesionalExternos")
        public List<ProfesionalExterno> filtrarProfesionalExternos(@WebParam(name = "buscar") String buscar) {
            Session s = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction trans = s.beginTransaction();
            Criteria c = s.createCriteria(ProfesionalExterno.class).add(Restrictions.or(Restrictions.or(Restrictions.or(Restrictions.like("rut", "%" + buscar + "%"),
                    Restrictions.like("nombres", "%" + buscar + "%")),
                    Restrictions.or(Restrictions.like("apellidoPaterno", "%" + buscar + "%"),
                    Restrictions.like("especialidad", "%" + buscar + "%"))),
                    (Restrictions.like("lugarDeTrabajo", "%" + buscar + "%"))));
            List l = c.list();
            s.close();
            return l;
        }




}
